<?php
//把这个文件放在项目根目录直接访问
$row = $dir = $html = $php = $js = $css = $png = $jpg = $txt = $other = $php1 = $php2 = 0;
function jiaMi($filename){
	global $row, $php1, $php2;
	$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	$T_k1 = str_shuffle($str);
	$T_k2 = str_shuffle($str);
	$vstr = file_get_contents($filename);
	$v1 = base64_encode($vstr);
	$c = strtr($v1, $T_k1, $T_k2);
	$c = $T_k1.$T_k2.$c;
	
	$q1 = "O00O0O";
	$q2 = "O0O000";
	$q3 = "O0OO00";
	$q4 = "OO0O00";
	$q5 = "OO0000";
	$q6 = "O00OO0";
	
	$s = '$'.$q6.'=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");$'.$q1.'=$'.$q6.'{3}.$'.$q6.'{6}.$'.$q6.'{33}.$'.$q6.'{30};$'.$q3.'=$'.$q6.'{33}.$'.$q6.'{10}.$'.$q6.'{24}.$'.$q6.'{10}.$'.$q6.'{24};$'.$q4.'=$'.$q3.'{0}.$'.$q6.'{18}.$'.$q6.'{3}.$'.$q3.'{0}.$'.$q3.'{1}.$'.$q6.'{24};$'.$q5.'=$'.$q6.'{7}.$'.$q6.'{13};$'.$q1.'.=$'.$q6.'{22}.$'.$q6.'{36}.$'.$q6.'{29}.$'.$q6.'{26}.$'.$q6.'{30}.$'.$q6.'{32}.$'.$q6.'{35}.$'.$q6.'{26}.$'.$q6.'{30};eval($'.$q1.'("'.base64_encode('$'.$q2.'="'.$c.'";eval(\'?>\'.$'.$q1.'($'.$q3.'($'.$q4.'($'.$q2.',$'.$q5.'*2),$'.$q4.'($'.$q2.',$'.$q5.',$'.$q5.'),$'.$q4.'($'.$q2.',0,$'.$q5.'))));').'"));'; 
	$s = '<?php '."\n".$s."\n".'?>';
	$fpp1 = fopen($filename, 'w');
	$back = fwrite($fpp1, $s);
	if($back){
		$php1++;
		echo $row."、文件： ".$filename." 加密成功！ 加密写入 ".$back." 字节。<br>";
	}else{
		$php2++;
		echo $row."、加密文件 ".$filename." 时出现写入出错！<br>";
	}
}

function getdir($path) {
	global $row,$dir,$html,$php,$js,$css,$png,$jpg,$txt,$other;
	$arr = scandir($path);
	foreach ($arr as $v) {
		if ($v != "." && $v != "..") {
			$row++;
			if (is_dir($path . "/" . $v)) {
				$dir++;
				echo "<hr>";
				echo $row."、目录：" . $path . "/" . $v;
				echo "<br>";
				getdir($path . "/" . $v);
			} else {
				$ext = substr($v, (strrpos($v, ".") + 1));
				if ($ext == 'html') {
					$html++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个HTML文件！";
				} elseif ($ext == 'php') {
					$php++;
					jiaMi($path."/".$v);
				} elseif ($ext == 'js') {
					$js++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个JS文件！";
				} elseif ($ext == 'css') {
					$css++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个CSS文件！";
				} elseif ($ext == 'png') {
					$png++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个png图片！";
				} elseif ($ext == 'jpg') {
					$jpg++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个jpg图片！";
				} elseif ($ext == 'txt') {
					$txt++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个txt文档！";
				} else {
					$other++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个其他文件！";
				}
				echo "<br>";
			}
		}
	}
}
function sta(){
	global $row,$dir,$html,$php,$js,$css,$png,$jpg,$txt,$other,$php1,$php2;
	echo "<hr>";
	getdir(".");

	echo "<hr><hr>";
	echo "本次解码统计：共递归文件夹 " . $dir . "个!";
	echo "<br>";
	echo "遍历的文件总计: " . ($html+$php+$js+$css+$png+$jpg+$txt+$other) . " 个!";
	echo "<br>";
	echo "共遍历HTML文件 " . $html . " 个!";
	echo "<br>";
	echo "共遍历PHP文件 " . $php . " 个!"." 其中加密成功 ".$php1." 个，加密失败 ".$php2." 个。";
	echo "<br>";
	echo "共遍历JS文件 " . $js . " 个!";
	echo "<br>";
	echo "共遍历CSS文件 " . $css . " 个!";
	echo "<br>";
	echo "共遍历png图片文件 " . $png . " 个!";
	echo "<br>";
	echo "共遍历jpg图片文件 " . $jpg . " 个!";
	echo "<br>";
	echo "共遍历txt文件 " . $txt . " 个!";
	echo "<br>";
	echo "共遍历其他文件 " . $other . " 个！<br>";
}
sta();
?>